﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;

namespace APITest.PingAnSign
{
    /// <summary>
    /// 平安万里通
    /// </summary>
    [System.ComponentModel.Composition.Export(typeof(G.APITest.Part.IAPIRequestPart))]
    public class Project : G.APITest.Part.NormalRequest
    {
        public Project()
        {
            this.ExtensionProjectProperties = new G.APITest.Config.KVPair[] 
            {
                new G.APITest.Config.KVPair(){ Key="APPSecret",Value="09FB84B1-D90E-4C14-84DB-DEE924A87B51"}
            };
        }

        protected override void DoSign(G.APITest.Config.APIProjectConfig config, G.APITest.Config.APIConfig api, System.Collections.Generic.Dictionary<string, string> paramDic)
        {
            base.DoSign(config, api, paramDic);
            paramDic.Add("authType", "md5");
            var data = paramDic.OrderBy(c => c.Key);
            string str = string.Empty;
            foreach (var item in data)
            {
                str += item.Key + item.Value;
            }
            string signStr = str + config.ExtensionProjectProperties.First(c => c.Key == "APPSecret").Value;
            string sign = System.Security.Cryptography.MD5.GetHashString(signStr).ToLower();
            paramDic.Add("sign", sign);
            this.RaiseStatusCallBack("签名字符串：" + signStr);
            this.RaiseStatusCallBack("签名结果：" + sign);
        }
    }
}
